NL126 carried an article by me about linking LB to a web server to produce dynamic web pages, like PERL, for example. If you read that, forget it all. It worked, but it was total rubbish - naff - uncool. It was over-complicated and cumbersome. It was daft!
Seriously, it was not that bad, but I have discovered a little trick of the Apache web server that makes things much easier than I thought. The new approach allows any number of tokens to be conveniently used. Read on!
The major problem I had using LB to generate dynamic pages was the difficulty of returning information from LB to the Web server. Last time I used 'server side includes' to accomplish this. This time I have written a very small external programme called 'printstring.exe' to provide the final link back to the Apache server. I have included the 'C' source code for this programme.
I have tested this with a 'local server' using a copy of Apache for Windows ( a widely available free http server). I first created a directory to hold my LB files, which I called 'lb_files', and I placed this within the 'htdocs' directory. the full path to this directory, on my machine, was
'c:/program files/apache group/apache/htdocs/lb_files'
I put into this directory all the files that this simple demonstration uses.
printstring.c
printstring.exe
index.html
basicform.html
volumeform.html
pictureform.html
readform.bas
volume.bas
picture.bas
tab2.jpg
tab3.jpg
XhairPos.jpg
mystyle.css
and two additional files
htmltocgi.bas
Alycecgi.bas
You need to include in this directory the LB support files (DLLs and SLLs) plus a copy of the runtime engine 'run401.exe', renamed to 'runtkn.exe'. You will then need to compile the three demonstration basic programmes to token files.
It is neccessary to make two changes to the default Apache configuration file. First include a section allowing cgi scripts to be run from the LB_FILES directory
<Directory "C:/Program Files/Apache Group/Apache/htdocs/lb_files">
Options ExecCGI
ScriptInterpreterSource registry
</Directory>
Secondly, uncomment a line defining cgi scripts, and add the .tkn extention to this line, so that it looks like this
AddHandler cgi-script .cgi .tkn
Finally, you need to make Windows associate files with the .tkn extention with 'runtkn.exe'. You do this (on Windows 98SE) by opening Windows Explorer, opening the 'options' menu item, selecting the 'file types' tab, and then adding or editing the properties for the .tkn extention.
Use one of the demo files as your template. There are various support subroutines and functions. There is also a main routine carrying the web page you are creating. In this subroutine, compose a string ( say, html$) that contains valid html statements, including this first line.
html$ = "Content-type:text/html" + chr$(13)+chr$(10)+chr$(13)+chr$(10)
Add further html statements, in the form of
html$ = html$ + "some html statement"
when your html is complete, then pass this string to the output routine, with
call outputstring html$
This subroutine simply passes HTML string to 'printstring.exe' which in turn prints this string to 'standard output', which is then recognised by the Apache server.
Your LB generated page should not have any GUI elements or print statements, and the html string must include only valid HTML statements, made with
html$ = html$ + " Your text here "
statements. This may seem limited, but all web pages are, ultimately, built in the same manner. Within the HTML, you can include references to images to display, and perhaps to animations and sound files etc. What you cannot do is use any GUI functions in your scripts. The user has no way of interacting with them. Even simple notices are dangerous. You may want to use them at key points in your script for testing, but you should not leave them in when you 'go live'.
You can use them for databases. You can use them for text/jpeg based adventure games. You can use them for catalogues and picture galleries. You cannot use them for Shoot'em ups (shame).
I have added two small LB programmes to the zip file. The first 'htmltocgi.bas', takes an HTML file and adds the neccessary wrapper code for use in an LB page. From the generated file you can cut and paste into you own programmes. The second, 'Alycecgi.bas', integrates this functionality with an HTML editor produced by Alyce Watson for the community some time ago. Thanks Alyce.
A disclaimer - I have not tested this for real, as I do not have suitable access to a real world server. I have used it with an Apache server on my own machine using loop back to Localhost. If anyone can set it up on a real server I would be interested in finding out how well it works.